//
//  BRMDayTimeView.m
//  BrezzeSaaS
//
//  Created by macos on 14.3.22.
//  Copyright © 2022 Brezze GWG. All rights reserved.
//

#import "BRMDayTimeView.h"


@interface BRMDayTimeView ()
{
    UIImageView *_trangleImg;
    QMUILabel *_timeL;
    UIImageView *_addImg;
    QMUIButton *_deleteBtn;
}
@end

@implementation BRMDayTimeView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)setIsAdd:(BOOL)isAdd {
    _isAdd = isAdd;
    
    _addImg.hidden = !isAdd;
    _timeL.hidden = isAdd;
    _trangleImg.hidden = isAdd;
}

- (void)setIsCanDele:(BOOL)isCanDele {
    _isCanDele = isCanDele;
    _deleteBtn.hidden = !isCanDele;
}

- (void)setIsEnble:(BOOL)isEnble {
    _isEnble = isEnble;
    self.alpha = isEnble ? 1 : 0.4;
}

- (void)toDelete {
    NSLog(@"%s",__func__);
    if (!self.isEnble) return;
    
    self.isAdd = YES;
    self.isCanDele = NO;
    
    if (self.deleteTime) {
        self.deleteTime(self);
    }
}

- (void)setTimeStr:(NSString *)timeStr {
    _timeStr = timeStr;
    _timeL.text = timeStr;
}

#pragma mark - UI --
- (void)setUI {
    
    self.layer.cornerRadius = 18;
    self.layer.borderColor = UIColorText1.CGColor;
    self.layer.borderWidth = 0.5;
    self.layer.masksToBounds = YES;
    self.backgroundColor = UIColorWhite;
    
    QMUILabel *timeL = [BRToolsView br_label:@"0:00 - 00:00" textColor:kColorTitle font:[UIFont fontM:12]];
    timeL.textAlignment = NSTextAlignmentCenter;
    [self addSubview:timeL];
    [timeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.offset(0);
        make.right.offset(-26);
        make.left.offset(26);
    }];
    
    QMUIButton *deBtn = [[QMUIButton alloc] init];
    [deBtn setImage:UIImageMake(@"info_delete") forState:UIControlStateNormal];
    [deBtn setTitle:@"" forState:UIControlStateNormal];
    deBtn.imageEdgeInsets = UIEdgeInsetsMake(-5, -7, 0, 0);
    [self addSubview:deBtn];
    [deBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(46);
        make.left.top.offset(0);
    }];
    [deBtn addTarget:self action:@selector(toDelete) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *img = [[UIImageView alloc] initWithImage:UIImageMake(@"arrow_trangle_down6")];
    [self addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(4);
        make.width.mas_equalTo(6);
        make.right.offset(-10);
        make.centerY.offset(0);
    }];
    
    UIImageView *addImg = [[UIImageView alloc] initWithImage:UIImageMake(@"marchant_timeAdd")];
    addImg.contentMode = UIViewContentModeCenter;
    [self addSubview:addImg];
    [addImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    _addImg = addImg;
    _trangleImg = img;
    _timeL = timeL;
    _deleteBtn = deBtn;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
